package com.blb.service.user.impl;


import com.blb.dao.user.impl.UserDaoImpl;
import com.blb.pojo.User;
import com.blb.service.user.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserDaoImpl userDao ;

    @Override
    public void register(User user) throws Exception {
        User selectByName = userDao.selectByName(user.getName());
        if (selectByName != null){
            throw new Exception("账户已经存在,不可重复注册");
        }else {
            userDao.register(user);
        }
    }


    @Override
    public User login(User user) throws Exception {
        User user1 = userDao.selectByName(user.getName());
        if(user1==null){
            throw new Exception("账号不存在");
        }
        if(!user1.getPass().equals(user.getPass())){
            throw new Exception("密码错误");
        }
        return user1;
    }

    @Override
    public User getByName(String name) throws Exception {
        return userDao.selectByName(name);
    }
}
